﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Xml;

namespace WebComTest.WebUI.Models.RequestManagers
{
    public static class HttpWebRequestExtention
    {
        public static void InsertSoapEnvelope(this HttpWebRequest webRequest, XmlDocument soapEnvelopeXml)
        {
            using (Stream stream = webRequest.GetRequestStream())
            {
                soapEnvelopeXml.Save(stream);
            }
        }

        public static void Authenticate(this HttpWebRequest webRequest, string user, string pwd)
        {
            string _auth = string.Format("{0}:{1}", user, pwd);

            webRequest.Headers[HttpRequestHeader.Authorization] =
                string.Format("Basic {0}", Convert.ToBase64String(Encoding.ASCII.GetBytes(_auth)));
        }
    }
}